package com.ruoyi.threeViolation.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.threeViolation.domain.ViolationRegister;
import com.ruoyi.threeViolation.mapper.ViolationRegisterMapper;
import com.ruoyi.threeViolation.vo.ViolationPenalizeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.threeViolation.mapper.ViolationPenalizeMapper;
import com.ruoyi.threeViolation.domain.ViolationPenalize;
import com.ruoyi.threeViolation.service.IViolationPenalizeService;

/**
 * 三违处罚Service业务层处理
 *
 * @author lth
 * @date 2023-12-18
 */
@Service
public class ViolationPenalizeServiceImpl implements IViolationPenalizeService
{
    @Autowired
    private ViolationPenalizeMapper violationPenalizeMapper;

    @Autowired
    private ViolationRegisterMapper violationRegisterMapper;

    /**
     * 查询三违处罚
     *
     * @param id 三违处罚主键
     * @return 三违处罚
     */
    @Override
    public ViolationPenalize selectViolationPenalizeById(String id)
    {
        return violationPenalizeMapper.selectViolationPenalizeById(id);
    }

    /**
     * 查询三违处罚列表
     *
     * @param violationPenalize 三违处罚
     * @return 三违处罚
     */
    @Override
    public List<ViolationPenalize> selectViolationPenalizeList(ViolationPenalize violationPenalize)
    {
        return violationPenalizeMapper.selectViolationPenalizeList(violationPenalize);
    }

    /**
     * 新增三违处罚
     *
     * @param violationPenalize 三违处罚
     * @return 结果
     */
    @Override
    public int insertViolationPenalize(ViolationPenalize violationPenalize)
    {
        return violationPenalizeMapper.insertViolationPenalize(violationPenalize);
    }

    /**
     * 修改三违处罚
     *
     * @param violationPenalize 三违处罚
     * @return 结果
     */
    @Override
    public int updateViolationPenalize(ViolationPenalize violationPenalize)
    {
        return violationPenalizeMapper.updateViolationPenalize(violationPenalize);
    }

    /**
     * 批量删除三违处罚
     *
     * @param ids 需要删除的三违处罚主键
     * @return 结果
     */
    @Override
    public int deleteViolationPenalizeByIds(String[] ids)
    {
        return violationPenalizeMapper.deleteViolationPenalizeByIds(ids);
    }

    /**
     * 删除三违处罚信息
     *
     * @param id 三违处罚主键
     * @return 结果
     */
    @Override
    public int deleteViolationPenalizeById(String id)
    {
        return violationPenalizeMapper.deleteViolationPenalizeById(id);
    }

    /**
     * 三违处罚列表
     */
    @Override
    public List<ViolationPenalize> penalizeList(ViolationPenalizeVo vo) {
        List<ViolationPenalize> violationPenalizeList = violationPenalizeMapper.getListByPenaltyBlacklist();
        List<ViolationPenalize> list = violationPenalizeList.stream().map(violationPenalize -> {
            String volationId = violationPenalize.getVolationId();
            if (StringUtils.isNotEmpty(volationId)) {
                ViolationPenalize violationPenalizeById = violationPenalizeMapper.selectViolationPenalizeByViolationId(volationId);
                return violationPenalizeById;
            } else {
                return null;
            }
        }).collect(Collectors.toList());

        return list;
    }

    /**         三违处罚黑名单列表
    * @Author lth
    * @Description //TODO
    * @Date 21:06 2023/12/20
    * @Param
    * @return
     **/
    @Override
    public List<ViolationPenalize> blackList(ViolationPenalizeVo vo) {
        String penaltyBlacklist = vo.getPenaltyBlacklist();
        List<ViolationPenalize> violationPenalizeList = violationPenalizeMapper.getBlacklist(penaltyBlacklist);
        return violationPenalizeList;
    }
}
